home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 2207 / 2207.xpi / chrome / cooliris.jar / content / cooliris / xmlhttpNew.js < prev   
Text File  |  2010-01-28  |  4KB  |  161 lines

  1. function cpvw_response(_1,_2,_3,_4,_5){
  2. this.xmlDoc=_1;
  3. this.responseText=_2;
  4. this.responseHeaders=_3;
  5. this.statusMesg=_4;
  6. this.hasErrors=(_5!=null);
  7. this.file=null;
  8. }
  9. function cpvw_httpClient(_6){
  10. this.objAct=_6;
  11. this.headers=null;
  12. this.channel=null;
  13. this.observerSerivce=null;
  14. this.timer=null;
  15. }
  16. cpvw_httpClient.prototype={topic:"http-on-modify-request",getObject:function(){
  17. return Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Components.interfaces.nsIXMLHttpRequest);
  18. },parseHeaders:function(_7){
  19. var _8=[];
  20. var _9=_7.split("\n");
  21. for(var i=0;i<_9.length;i++){
  22. var _b=_9[i];
  23. var _c=_b.match(/(.*?):(.*)/);
  24. if(_c!=null){
  25. var _d=_c[1];
  26. var _e=_c[2];
  27. _8[_d]=_e;
  28. }
  29. }
  30. return _8;
  31. },QueryInterface:function(_f){
  32. if(_f.equals(Components.interfaces.nsISupports)||_f.equals(Components.interfaces.nsIObserver)||_f.equals(Components.interfaces.nsITimerCallback)){
  33. return this;
  34. }
  35. throw Components.results.NS_ERROR_NO_INTERFACE;
  36. },observe:function(_10,_11,_12){
  37. if(_11=="xpcom-shutdown"){
  38. this.clean();
  39. }
  40. if(_11!=this.topic||_10!=this.channel){
  41. return;
  42. }
  43. if(this.headers instanceof Array){
  44. for(var i=0;i<this.headers.length;i++){
  45. this.channel.setRequestHeader(this.headers[i].name,this.headers[i].value,false);
  46. }
  47. }
  48. this.clean();
  49. },notify:function(){
  50. this.clean();
  51. },clean:function(){
  52. var _14=Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
  53. _14.removeObserver(this,this.topic);
  54. if(this.timer){
  55. this.timer.cancel();
  56. this.timer=null;
  57. }
  58. },doRequest:function(_15,_16,_17,_18,_19,_1a,_1b){
  59. var _1c=this;
  60. try{
  61. var _1d=this.getObject();
  62. if(_17!=""){
  63. _17="?"+_17;
  64. }
  65. var _1e=_16+_17;
  66. _1d.open(_15,_1e,!_19);
  67. _1d.channel.loadFlags|=Components.interfaces.nsIRequest.LOAD_BYPASS_CACHE;
  68. if(_15=="POST"){
  69. _1d.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=utf-8");
  70. }
  71. var _1f=_1d.channel.QueryInterface(Components.interfaces.nsIHttpChannel);
  72. _1f.redirectionLimit=0;
  73. this.channel=_1f;
  74. this.headers=_1a;
  75. var _20=Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
  76. _20.addObserver(this,this.topic,false);
  77. _20.addObserver(this,"xpcom-shutdown",false);
  78. this.timer=Components.classes["@mozilla.org/timer;1"].createInstance(Components.interfaces.nsITimer);
  79. this.timer.initWithCallback(this,15000,this.timer.TYPE_ONE_SHOT);
  80. this.redirectCount=0;
  81. _1d.send(_18);
  82. var _21=Components.classes["@mozilla.org/xmlextras/domparser;1"].createInstance(Components.interfaces.nsIDOMParser);
  83. if(_19){
  84. if(_1d.status>=200&&_1d.status<300){
  85. var _22=_21.parseFromString(_1d.responseText,"text/xml");
  86. var _23=new cpvw_response(_22,_1d.responseText,_1c.parseHeaders(_1d.getAllResponseHeaders()));
  87. if(_1b){
  88. _1b.call(_1c.objAct,_23);
  89. }
  90. return _23;
  91. }else{
  92. var _24="Error connecting! Try again - "+_1d.status+" "+_1d.statusText;
  93. var _22=null;
  94. try{
  95. _22=_21.parseFromString(_1d.responseText,"text/xml");
  96. }
  97. catch(ex2){
  98. _22=null;
  99. _24=ex2;
  100. }
  101. if(_22!=null&&_22.getElementsByTagName("Message")[0]){
  102. _24=_22.getElementsByTagName("Message")[0].firstChild.nodeValue;
  103. }
  104. var _23=new cpvw_response(_22,_1d.responseText,_1c.parseHeaders(_1d.getAllResponseHeaders()),_24,true);
  105. if(_1b){
  106. _1b.call(_1c.objAct,_23);
  107. }
  108. return _23;
  109. }
  110. }else{
  111. _1d.onreadystatechange=function(){
  112. if(_1d.readyState!=4){
  113. return;
  114. }else{
  115. if(_1d.status>=200&&_1d.status<300){
  116. var _25=_1d.responseXML;
  117. var _26=new cpvw_response(_25,_1d.responseText,_1c.parseHeaders(_1d.getAllResponseHeaders()));
  118. if(_1b){
  119. _1b.call(_1c.objAct,_26);
  120. }
  121. return _26;
  122. }else{
  123. if(_1d.status>=300&&_1d.status<400){
  124. var _27=_1c.parseHeaders(_1d.getAllResponseHeaders());
  125. if(_27["Location"]!=null&&_1c.redirectCount<3){
  126. _1c.redirectCount++;
  127. _1c.doRequest(_15,_27["Location"],_17,_18,_19,_1a,_1b);
  128. return;
  129. }
  130. }
  131. var _28="Error connecting! Try again - "+_1d.status+" "+_1d.statusText;
  132. var _25=null;
  133. try{
  134. _25=_21.parseFromString(_1d.responseText,"text/xml");
  135. }
  136. catch(ex2){
  137. _25=null;
  138. _28=ex2;
  139. }
  140. if(_25!=null&&_25.getElementsByTagName("Message")[0]){
  141. _28=_25.getElementsByTagName("Message")[0].firstChild.nodeValue;
  142. }
  143. var _26=new cpvw_response(_25,_1d.responseText,_1d.getAllResponseHeaders(),_28,true);
  144. if(_1b){
  145. _1b.call(_1c.objAct,_26);
  146. }
  147. return false;
  148. }
  149. }
  150. };
  151. }
  152. }
  153. catch(ex){
  154. var _23=new cpvw_response(null,"",null,ex,true);
  155. if(_1b){
  156. _1b.call(_1c.objAct,_23);
  157. }
  158. }
  159. }};
  160.  
  161.